package com.mbc.rmt.manager;

import java.sql.SQLException;
import java.util.List;

import com.mbc.common.exception.DataDuplicationException;
import com.mbc.common.manager.AbstractMgr;
import com.mbc.common.param.CriteriaParams;
import com.mbc.common.utils.KeyGenerator;
import com.mbc.rmt.dao.ACGroupDetailDAO;
import com.mbc.rmt.dao.RemittanceDAOFactory;
import com.mbc.rmt.data.ACGroupDetailDataList;
import com.mbc.rmt.entities.ACGroupDetail;

public class ACGroupDetailMgr extends AbstractMgr {

	private ACGroupDetailDAO acgroupdetailDAO;

	public ACGroupDetailMgr() {
	}

	public ACGroupDetailMgr(String sessionId) {
		this.sessionId = sessionId;
	}

	public void create(ACGroupDetail entity) throws Exception {
		openConnection();
		try {
			acgroupdetailDAO = RemittanceDAOFactory
					.getACGroupDetailDAO(dbManager.getConnection());
			entity.setAcgroupdetailId(KeyGenerator.generateKey(getConnection()));
			acgroupdetailDAO.create(entity);
		} catch (SQLException e) {
			if (DataDuplicationException.UNIQUE_KEY_ERROR_CODE == e
					.getErrorCode())
				throw new DataDuplicationException(e.getMessage());
			else
				throw e;
		} finally {
			closeConnection();
		}
	}

	public void update(ACGroupDetail entity) throws Exception {
		openConnection();
		try {
			acgroupdetailDAO = RemittanceDAOFactory
					.getACGroupDetailDAO(dbManager.getConnection());
			acgroupdetailDAO.update(entity);
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}

	public void delete(long key) throws Exception {
		openConnection();
		try {
			acgroupdetailDAO = RemittanceDAOFactory
					.getACGroupDetailDAO(dbManager.getConnection());
			acgroupdetailDAO.delete(key);
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}

	public ACGroupDetail find(long key) throws Exception {
		openConnection();
		try {
			acgroupdetailDAO = RemittanceDAOFactory
					.getACGroupDetailDAO(dbManager.getConnection());
			return acgroupdetailDAO.find(key);
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}

	public ACGroupDetail findByCode(String code,long branchId) throws Exception {
		openConnection();
		try {
			acgroupdetailDAO = RemittanceDAOFactory
					.getACGroupDetailDAO(dbManager.getConnection());
			return acgroupdetailDAO.findByCode(code,branchId);
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}

	public List<ACGroupDetail> findAll() throws Exception {
		openConnection();
		try {
			acgroupdetailDAO = RemittanceDAOFactory
					.getACGroupDetailDAO(dbManager.getConnection());
			return acgroupdetailDAO.findAll();
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}

	public ACGroupDetailDataList findACGroupDetails(CriteriaParams cri)
			throws Exception {
		openConnection();
		try {
			acgroupdetailDAO = RemittanceDAOFactory
					.getACGroupDetailDAO(dbManager.getConnection());
			return acgroupdetailDAO.findACGroupDetails(cri);
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}

	public List<ACGroupDetail> getACGroupDetailList(ACGroupDetail info)
			throws Exception {
		openConnection();
		try {
			acgroupdetailDAO = RemittanceDAOFactory
					.getACGroupDetailDAO(dbManager.getConnection());
			return acgroupdetailDAO.getACGroupDetailList(info);
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}
}
